
require 'thefox-ext'

module TheFox
	module VieTra
		
		class Wait
			
			MAX_POINTS = 20
			#PROGRESS_CHARS = ['|', '/', '-', '\\', '|', '']
			PROGRESS_CHARS = %w[. o O 0 ° ^ |]
			
			def initialize(seconds)
				@seconds = seconds
			end
			
			def wait
				if @seconds <= MAX_POINTS
					print '|'
					print '-' * @seconds
					print '|'
					Console.cursor_jump_to_column(2)
					
					@seconds.times do |n|
						print '#'
						sleep 1
					end
					
					Console.cursor_jump_to_column(2)
					print ' ' * @seconds
				else
					per_point_time = @seconds.to_f / MAX_POINTS.to_f
					per_char_time = per_point_time / PROGRESS_CHARS.count.to_f
					
					#puts "pcc: #{PROGRESS_CHARS.count}"
					#puts "ppt: #{per_point_time}"
					#puts "pct: #{per_char_time}"
					
					print '|'
					print '-' * MAX_POINTS
					print '|'
					Console.cursor_jump_to_column(2)
					
					MAX_POINTS.times do |n|
						PROGRESS_CHARS.each do |char|
							print char
							
							sleep per_char_time
							
							Console.cursor_left
						end
						print '#'
					end
				end
			end
			
		end
		
	end
end
			